
#ifndef _YDLIDAR_GS2_H_
#define _YDLIDAR_GS2_H_


#include "stdint.h"
#include "ringbuff.h"

#define DATA_LENGTH_DISTANCE_FRAME  (327 - 1)
#define DATA_LENGTH_PARAM_FRAME     (14 - 1)

#define DATA_END_HOLD_TIME_MS   3

#define GS2_SEND_PERIOD_LIMIT_MS  55

typedef enum
{
	GS2_LEFT = 0,
	GS2_RIGHT 

}ENUM_GS2_NUM;

typedef enum
{
	DATA_FRAME = 0,
	PARAM_FRAME

}ENUM_GS2_FRAME_TYPE;

typedef struct
{	
	union
	{
		struct
		{
			uint16_t headH;
			uint16_t headL;
			uint8_t  address;
			uint8_t  type;
			uint16_t length;
			uint16_t environment;
			uint16_t data[160];
			uint8_t  checksum;		
		
		}frame;
		
		uint8_t byte[2+2+1+1+2+2+320+1];
		
	}distance;
	
	union
	{
		struct
		{
			uint16_t headH;
			uint16_t headL;
			uint8_t  address;
			uint8_t  type;
			uint16_t length;
			uint16_t K0;
			uint16_t B0;
			uint16_t K1;
			uint16_t B1;
			uint8_t  Bias;
			uint8_t  checksum;
		
		}frame;
		
		uint8_t byte[18];
		
	}param;
	
	
	ENUM_GS2_NUM num;
	STR_RINGBUF* sendbuf;
	STR_RINGBUF* recbuf;
	uint8_t read_data_send;
	uint8_t read_param_flg;
	
	uint16_t read_data_cnt;
	
	uint16_t rece_time_stamp;
	uint16_t store_time_stamp;
	
	uint8_t  data_end_cnt;
		
}STR_GS2_HDL;

extern STR_GS2_HDL gs2Hdl[2];

extern void GS2_comm_frame_init(void);
extern void GS2_data_analysis(STR_GS2_HDL *hdl);
extern void GS2_wall_sensor_run(void);


#endif


